package com.sun.data_sort;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

public class SortDriver {
    public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {
        Configuration conf = new Configuration();
        Job job = Job.getInstance(conf);

        // 设置驱动类
        job.setJarByClass(SortDriver.class);

        // 设置map和reducer
        job.setMapperClass(SortMapper.class);
        job.setReducerClass(SortReducer.class);

        // 设置map输出类型
        job.setMapOutputKeyClass(IntWritable.class);
        job.setMapOutputValueClass(IntWritable.class);

        // 设置最终输出kv类型
        job.setOutputKeyClass(IntWritable.class);
        job.setOutputValueClass(IntWritable.class);

        // 设置输入和输出路径
        FileInputFormat.setInputPaths(job,
                new Path("E:\\bigdatademo\\wordcountdemo\\src\\main\\java\\com\\sun\\data_sort\\data"));
        FileOutputFormat.setOutputPath(job, new Path("E:\\bigdatademo\\wordcountdemo\\src\\main\\java\\com\\sun\\data_sort\\output"));

        // 提交
        boolean flag = job.waitForCompletion(true);
        System.exit(flag ? 0 : 1);
    }
}
